import { useRequest } from 'umi';

import { getDicTypeList } from '@/pages/SystemController/DictionaryTreeController/service';
import { message } from 'antd';

export const useDictionaryTypeTree = () => {
  const requestTree = useRequest(
    () => {
      return getDicTypeList();
    },
    {
      manual: false,
      onSuccess: (res) => {
        if (!res?.msgFlag) {
          message.error(res?.msg ?? '获取字典类型失败');
        }
      },
    },
  );

  const reloadTree = requestTree.run;
  const treeData = requestTree.data?.obj;
  const treeLoading = requestTree.loading;
  return {
    reloadTree,
    treeData,
    treeLoading,
  };
};
